#include "snack.h"
#include<QPoint>
//好家伙这是个啥你得知道
snack::snack()
{
    //初始化小蛇
    list.push_back(QRect(300,300,30,30));
    score=0;
}

void snack::up_direction()
{
    //涉及到边界问题
    QPoint lefttop;
    QPoint rightbottom;
    QRect head=list.front();
    if(head.y()<=0)
    {
        lefttop=QPoint(head.x(),570);
    }
    else
    {
        lefttop=QPoint(head.x(),head.y()-30);
    }
    rightbottom=QPoint(lefttop.x()+30,lefttop.y()+30);
    list.push_front(QRect(lefttop,rightbottom));
}

void snack::down_direction()
{
    QPoint lefttop;
    QPoint rightbottom;
    QRect head=list.front();
    if(head.y()+30==600)
    {
        lefttop=QPoint(head.x(),0);
    }
    else
    {
        lefttop=QPoint(head.x(),head.y()+30);
    }
    rightbottom=QPoint(lefttop.x()+30,lefttop.y()+30);
    list.push_front(QRect(lefttop,rightbottom));
}

void snack::left_direction()
{
    QPoint lefttop;
    QPoint rightbottom;
    QRect head=list.front();
    if(head.x()<=0)
    {
        lefttop=QPoint(570,head.y());
    }
    else
    {
        lefttop=QPoint(head.x()-30,head.y());
    }
    rightbottom=QPoint(lefttop.x()+30,lefttop.y()+30);
    list.push_front(QRect(lefttop,rightbottom));
}

void snack::right_direction()
{
    QPoint lefttop;
    QPoint rightbottom;
    QRect head=list.front();
    if(head.x()+30==600)
    {
        lefttop=QPoint(0,head.y());
    }
    else
    {
        lefttop=QPoint(head.x()+30,head.y());
    }
    rightbottom=QPoint(lefttop.x()+30,lefttop.y()+30);
    list.push_front(QRect(lefttop,rightbottom));
}


